Interfacing With the Chooser
When the user selects your driver in the Chooser, the Chooser sends certain Chooser messages to you by calling theDevice
function, which is the interface for the package ('PACK'
) resource. You need to provide a version of this function to provide Chooser support for your driver. The package resource and its use are described in Inside Macintosh: More Macintosh Toolbox.QuickDraw GX provides the
GXHandleChooserMessage
function, which takes care of most of the work of handling the Chooser package code for you. What you need to do is create aDevice
function, take appropriate action for messages that you need to handle, and pass the parameters on to theGXHandleChooserMessage
function. Listing 5-3 shows the ImageWriter II printer driver implementation of theDevice
function.Listing 5-3 The
Device
function for the ImageWriter II printer driver
pascal OSErr Device(short message, short caller, StringPtr objName, StringPtr zoneName, ListHandle theList, long p2) { OSErr anErr = noErr; extern Str31 gDriverName; StringPtr pDriverName = &gDriverName; extern gxJob gJob; gxJob *pJob = &gJob; /* start up QuickDraw GX to begin with */ if (message == initializeMsg) { FCBPBRec pb; /* determine the driver name */ pb.ioCompletion = nil; pb.ioNamePtr = pDriverName; pb.ioVRefNum = 0; pb.ioRefNum = CurResFile(); pb.ioFCBIndx = 0; anErr = PBGetFCBInfo(&pb, false); *pJob = nil; if (anErr == noErr) { GXEnterGraphics(); anErr = GXInitPrinting(); if (anErr == noErr) anErr = GXNewJob(pJob); } } /* let the system handle the choosing */ if (anErr == noErr) anErr = GXHandleChooserMessage(*pJob, pDriverName, message, caller, objName, zoneName, theList, p2); /* shut down QuickDraw GX when done */ if ( (message == terminateMsg) && (p2 == terminateMsg) ) { if (*pJob != nil) GXDisposeJob(*pJob); GXExitPrinting(); GXExitGraphics(); } return(anErr); }The only Chooser messages that the ImageWriter II printer driver needs to do something special with areinitializeMsg
andterminateMsg
. When the Chooser sendsinitializeMsg
, the ImageWriter II driver initializes QuickDraw GX printing before passing the message along. And when the Chooser sends theterminateMsg
message, the ImageWriter II driver terminates QuickDraw GX printing after passing the message along. The Chooser messages are described in Inside Macintosh: Devices.
Main | Page One | What's New | Apple Computer, Inc. | Find It | Contact Us | Help